module vga_display #(
	parameter	H_DISP	= 10'd640,		    //分辨率(行)
	parameter	V_DISP	= 10'd480		    //分辨率(列)
)
(
	input					vga_clk,		//VGA驱动时钟
	input					sys_rst_n,		//复位信号
	
	input			[12:0]	pixel_xpos,		//像素点横坐标
	input			[12:0]	pixel_ypos,		//像素点纵坐标
	output      reg	[11:0]	pixel_data		//像素点数据
);

	localparam POS_X  = H_DISP / 2 - 10'd32;//字符区域起始点横坐标
	localparam POS_Y  = V_DISP / 2 - 10'd8; //字符区域起始点纵坐标
	localparam WIDTH  = 10'd64;             //字符区域宽度
	localparam HEIGHT = 10'd16;             //字符区域高度
	localparam RED    = 12'hf00;     		//字符颜色
	localparam BLUE   = 12'h00f;     		//字符区域背景色
	localparam BLACK  = 12'h000;     		//屏幕背景色

	//reg define
	reg  [63:0] char[15:0];                 //字符数组

	//wire define   
	wire [ 9:0] x_cnt;
	wire [ 9:0] y_cnt;

	//*****************************************************
	//**                    main code
	//*****************************************************
	assign x_cnt = pixel_xpos - POS_X;              //像素点相对于字符区域起始点水平坐标
	assign y_cnt = pixel_ypos - POS_Y;              //像素点相对于字符区域起始点竖直坐标

	//给字符数组赋值，显示汉字“正点原子”，汉字大小为16*16
	always @(posedge vga_clk) begin
		 char[0]  <= 64'h0000000000000000;
		 char[1]  <= 64'h0000000000000000;
		 char[2]  <= 64'h0880000000100000;
		 char[3]  <= 64'h0CC0080401101FFC;
		 char[4]  <= 64'h088408FE11101108;
		 char[5]  <= 64'h11FE0A0811101FF8;
		 char[6]  <= 64'h11247F1011161108;
		 char[7]  <= 64'h32381A12FFFF1FF8;
		 char[8]  <= 64'h552013FF11101348;
		 char[9]  <= 64'h5128121011100620;
		 char[10] <= 64'h1324341011F01E3F;    
		 char[11] <= 64'h12260C1011106624;
		 char[12] <= 64'h14260E1010040420;
		 char[13] <= 64'h19A013D01FFE0C20;
		 char[14] <= 64'h1060603010003020;
		 char[15] <= 64'h0000000000000000;
	end

	//给不同的区域绘制不同的颜色
	always @(posedge vga_clk or negedge sys_rst_n) begin         
		 if (!sys_rst_n) 
			  pixel_data <= BLACK;
		 else begin
			  if((pixel_xpos >= POS_X) && (pixel_xpos < POS_X + WIDTH)
				 && (pixel_ypos >= POS_Y) && (pixel_ypos < POS_Y + HEIGHT)) begin
					if(char[y_cnt][10'd63 - x_cnt])
						 pixel_data <= RED;              //绘制字符为红色
					else
						 pixel_data <= BLUE;             //绘制字符区域背景为蓝色      
			  end
			  else
					pixel_data <= BLACK;                //绘制屏幕背景为黑色
		 end
	end

endmodule 